<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link href="${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl/userModule/page/css/authority.css" rel="stylesheet" type="text/css">
<title>样式管理</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/validate.js">
</script>
</head>
<body>
<div id="cssThemes" style="width:100%"></div>
</body>
</html>
<script>
var userId = '${__SATURN_AUTORITY_USER__.id}';
Ext.onReady(function(){

	var cssArray = [['default','Ext Blue'],
					['gray','Gray Theme'],
					['chocolate','Chocolate Theme'],
					['peppermint','Peppermint Theme'],
					['silverCherry','SilverCherry Theme'],
					['black','Black Theme'],
					['green','Green Theme'],
					['darkgray','Darkgray Theme'],
					['indigo','Indigo Theme'],
					['olive','Olive Theme'],
					['darkgray','Darkgray Theme'],
					['purple','Purple Theme'],
					['slate','Slate Theme'],
					['slickness','Slickness Theme']];
					
	var cssStore = new Ext.data.SimpleStore({
		fields:[{name:'key'},{name:'value'}]
	});
	
	cssStore.loadData(cssArray);
    
    var cssThemes = new Ext.FormPanel({
        frame:true,
        title: '样式管理',
        bodyStyle:'padding:5px 5px 0',
        collapsible:true,
        renderTo:'cssThemes', 
        items: [{
            layout:'column',
            items:[{
                columnWidth:.5,
                layout: 'form', 
                items: [{
                    xtype:'textfield',
                    fieldLabel: '用户',
                    name: 'userSerialno_show',
                    id:'userSerialno_show',
                    anchor:'95%',
                    value:userId,
                    disabled:true
                },{
                	xtype:'textfield',
                    name: 'userSerialno',
                    id:'userSerialno',
					inputType:'hidden',
					hidden:true,
					value:userId
                }]
            },{
                columnWidth:.5,
                layout: 'form',
                items: [{
                    xtype:'combo',
                    fieldLabel: '样式主题',
                    name: 'theme_show',
                    id:'theme_show',
                    store: cssStore,
			        displayField:'value',
			        valueField :'key', 
			        hiddenName: 'cssTheme',
			        typeAhead: true,
			        mode: 'local',
			        forceSelection: true,
			        triggerAction: 'all',
			        selectOnFocus:true,
			        editable: false,
                    anchor:'95%'
                }]
            }]
        }],
        buttons:[{
        	text:'修改',
        	handler:function(){
        		cssThemes.form.submit({
	        		waitTitle:"提交" , 
	        		waitMsg:"提交数据中...",
        			url: '${pageContext.request.contextPath}/edu.ccut.saturn.manager.css.impl::/cssModule/ExtAction/UpdateUserCssTheme.action', 
	                success : function(form, action) {
	                		var myResult = Ext.util.JSON.decode(action.response.responseText);
	                		Ext.MessageBox.alert('信息','修改成功',function(){
	                				window.top.location.reload();
	                		})
	               },
	               failure : function(form, action) {
                       	Ext.MessageBox.show({
                             title: '信息',
                             msg: '对不起，与后台联系发生错误！',
                             buttons: Ext.MessageBox.OK,
                             icon: Ext.MessageBox.ERROR
                        });
	              },
	              params : {
	              		theme:document.getElementById('cssTheme').value
	              }
        		});
        	}
        }]
    });
    
    function getTheme(){
		Ext.Ajax.request({
		     method : 'POST', 
		     url: '${pageContext.request.contextPath}/edu.ccut.saturn.manager.css.impl::/cssModule/ExtAction/QueryForUserCssTheme.action',                  //发送到页面
		     success:function(request){              
		       	var myResult = Ext.util.JSON.decode(request.responseText);
		       	Ext.get("cssTheme").dom.value = myResult.mapList[0].CSSKEY;  
		       	for(var i = 0, n = cssArray.length; i < n; i++){
		       		if(cssArray[i][0] == Ext.get("cssTheme").dom.value){
		       			Ext.get("theme_show").dom.value = cssArray[i][1];
						cssThemes.findByType("combo")[0].emptyText = cssArray[i][1];
		       			break;
		       		}
		       	}
		     },
		     failure:function(){
		       	Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
		     }
     	});
    }
    getTheme();
});
</script>